package core

import (
	"context"
	"github.com/redis/go-redis/v9"
	"github.com/sirupsen/logrus"
	"go_blok/server/global"
)

func InitRedis() *redis.Client {
	r := global.Config.Redis
	rc := redis.NewClient(&redis.Options{
		Addr:     r.Addr,
		Password: r.Password,
		DB:       r.DB,
	})
	_, err := rc.Ping(context.Background()).Result()
	if err != nil {
		logrus.Fatal("redis连接失败", err)
	}
	logrus.Info("redis连接成功")
	return rc
}
